//引入API文件直接进行请求
import * as api from '@/utils/api.js'
const state={
    cartList:[]
};
const mutations={
    GETCARTLIST(state,cartList){
        state.cartList=cartList
    }
};
const actions={
    async cartList({commit}){
        const {data:res}=await api.cartList()
        commit('GETCARTLIST',res)
      },
      async delCart({commit},skuid){
        console.log(commit)
        const res=await api.delCart(skuid)
        if (res.code===200) {
            return 'ok'
        }else{
            return Promise.reject(new Error('faile'))
        }
      }
};
const getters={
    cartList(state){
        return state.cartList[0] || {}
    },

    cartInfoList(state){
        return state.cartList[0]!==undefined ?  state.cartList[0].cartInfoList : []
    }
}
export default{
    state,
    mutations,
    actions,
    getters
}